////
////  HDExamTableViewCell.swift
////  Excited
////
////  Created by X140Yu on 6/15/16.
////  Copyright © 2016 X140Yu. All rights reserved.
////
//
//import UIKit
//
//class HDExamTableViewCell: UITableViewCell {
//    @IBOutlet weak var nameLabel: UILabel!
//    @IBOutlet weak var dateLabel: UILabel!
//    @IBOutlet weak var timeLabel: UILabel!
//    @IBOutlet weak var locationLabel: UILabel!
//    @IBOutlet weak var timeFlagLabel: UILabel!
//    
//    
//    func setExam(examInfo: HDExam) {
//        nameLabel.text = examInfo.cname
//        dateLabel.text = examInfo.date
//        timeLabel.text = examInfo.time
//        locationLabel.text = examInfo.classroom
//        
//        let dateFormatter = NSDateFormatter()
//        dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
//        let startTimeString = examInfo.time![0, 5]
//        let startDate = dateFormatter.dateFromString("\(examInfo.date!) \(startTimeString)")!
//        
//        let endTimeString = examInfo.time![6, 11]
//        
//        let endDate = dateFormatter.dateFromString("\(examInfo.date!) \(endTimeString)")!
//        
//        let currentDate = NSDate()
//        
//        if currentDate.isLessThanDate(startDate) {
//            // not started
//            timeFlagLabel.backgroundColor = UIColor(red: 249.0/255, green: 64.0/255, blue: 61.0/255, alpha: 1.0)
//            timeFlagLabel.text = "未开始"
//        } else if currentDate.isGreaterThanDate(endDate) {
//            // has ended
//            timeFlagLabel.backgroundColor = UIColor(red: 2.0/255, green: 153.0/255, blue: 58.0/255, alpha: 1.0)
//            timeFlagLabel.text = "己结束"
//        } else {
//            // 正在考试 do nothing...
//        }
//
//    }
//
//    override func awakeFromNib() {
//        super.awakeFromNib()
//        // Initialization code
//    }
//
//    override func setSelected(selected: Bool, animated: Bool) {
//        super.setSelected(selected, animated: animated)
//
//        // Configure the view for the selected state
//    }
//
//}
//
//extension String {
//    subscript (start: Int, end: Int) -> String {
//        let s = self.startIndex.advancedBy(start)
//        let e = end < 0 ? self.endIndex.advancedBy(end) : self.startIndex.advancedBy(end)
//        return self[Range(start: s, end: e)]
//    }
//}
//
//// http://stackoverflow.com/questions/26198526/nsdate-comparison-using-swift
//extension NSDate {
//    func isGreaterThanDate(dateToCompare: NSDate) -> Bool {
//        //Declare Variables
//        var isGreater = false
//        
//        //Compare Values
//        if self.compare(dateToCompare) == NSComparisonResult.OrderedDescending {
//            isGreater = true
//        }
//        
//        //Return Result
//        return isGreater
//    }
//    
//    func isLessThanDate(dateToCompare: NSDate) -> Bool {
//        //Declare Variables
//        var isLess = false
//        
//        //Compare Values
//        if self.compare(dateToCompare) == NSComparisonResult.OrderedAscending {
//            isLess = true
//        }
//        
//        //Return Result
//        return isLess
//    }
//}